package com.lzgcoding.onlineshopapp.nav

import androidx.compose.runtime.Composable
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.toRoute
import com.lzgcoding.onlineshopapp.feature.detail.DetailScreen
import com.lzgcoding.onlineshopapp.feature.main.MainNav
import com.lzgcoding.onlineshopapp.feature.splash.SplashScreen

@Composable
fun App() {
    val navController = rememberNavController()

    NavHost(
        navController = navController,
        startDestination = AppRoute.Splash
    ) {
        composable<AppRoute.Splash> {
            SplashScreen {
                navController.navigate(it) {
                    popUpTo(AppRoute.Splash) {
                        inclusive = true
                    }
                    launchSingleTop = true
                }
            }
        }

        composable<AppRoute.MainNav> { MainNav(appNavController = navController) }
        composable<AppRoute.Detail> {
            DetailScreen(
                params = it.toRoute()
            ) {
                navController.navigateUp()
            }
        }
    }
}